VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsGame"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'====================================================================================
'clsGame - A class that controls when you start playing until you lose your last life
'====================================================================================
Option Explicit

'Things in the Game class follow you from level to level (i.e. score)
Public Lives As Long         'Number of lives the player has
Public Score As Long         'The player's current score

Public TotalCookies As Long  'Total cookies eaten all game
Public TotalGhosts As Long   'Total number of ghosts eaten all game
Public TotalTime As Long     'Total time playing the game (in seconds)

Public LevelNumber As Long   'The current level number the player is on

'If you double click on a level file on disk, that level is loaded and same level
'is played over and over until you eventually die. The number of times you've
'completed the level is the number of "Rounds".
Public IsSingleLevel As Boolean
Public Round As Long         'How many times the player has played the file.

'====================================================================================
'StartGame: Begin playing the game, load the first level...
'====================================================================================
Public Function StartGame(Optional ByVal LevelFile As String)
    Dim LevelCount As Long, Temp As String, K As Long
    'Starts the player's game. Sets the lives, and score to start with and
    'starts at level 1 in the sequence
    Me.Lives = 3: Me.Score = 0
    Me.TotalCookies = 0: Me.TotalTime = 0: Me.TotalGhosts = 0
    
    'Clear the title screen
    Set GameScreen = Nothing
    
    'If no level is passed to play, load the level sequence
    If LevelFile = "" Then
        'Load the level sequence the player will follow through the game
        Open AppPath & "\Data\Sequence.dat" For Input As #1
            'Get the number of levels (1-based)
            Input #1, LevelCount
            ReDim Project.LevelSequence(LevelCount - 1) As PM_LEVELSEQUENCE
            'Read each level sequence in
            For K = 0 To (LevelCount - 1)
                Input #1, Project.LevelSequence(K).Title1
                Input #1, Project.LevelSequence(K).Title2
                Input #1, Temp
                Project.LevelSequence(K).LevelFile = AppPath & "\data\" & Temp
                Input #1, Project.LevelSequence(K).LevelTheme
                Input #1, Project.LevelSequence(K).DiffLevel
            Next K
        Close #1
        Game.IsSingleLevel = False
    Else
        'Use the single level sent to game
        ReDim Project.LevelSequence(0) As PM_LEVELSEQUENCE
        Project.LevelSequence(0).LevelFile = LevelFile
        Project.LevelSequence(0).LevelTheme = ""    'Use the theme in the file
        Project.LevelSequence(0).DiffLevel = -1     'Use the difflevel in the file
        Game.IsSingleLevel = True
    End If
    
    'Load Level 1 in the sequence
    Me.LevelNumber = 0: GoToLevel LevelNumber
    
    'Change over to the level screen
    GameMode = GM_Play
End Function

'====================================================================================
'GoToLevel: Loads a level in the sequence and sets theme and difficulty
'====================================================================================
Public Function GoToLevel(ByVal LevelNumber As Long)
    'Clear any existing level from memory, and prepare a new level
    Set GameScreen = Nothing
    Set GameScreen = New IScreen_Level
    
    'Load the level and override the theme and difficulty inside the file to that
    'of the player's current progress in the game
    GameMode = GM_Play: ScreenMode = SM_Load
End Function

'====================================================================================
'NextLevel: Go to the next level in the sequence
'====================================================================================
Public Function NextLevel()
    'When the player completes a level (level.LevelComplete) this function is called
    'to move to the next level in the game (StartUp.LevelSequence)
    
    'If a game was started by opening a level file from disk, just replay.
    '(only one level in the level sequence)
    If Game.IsSingleLevel = True Then
        'Add one to the number of rounds completed.
        Me.Round = Me.Round + 1
        GoToLevel LevelNumber
        
    'If the player just completed the last level, they've completed the game!
    ElseIf Me.LevelNumber = UBound(Project.LevelSequence) Then
        '!//GAME COMPLETE!
        Project.StartHighScoreScreen False
        
    Else
        'Add one to the current level, load next level file
        Me.LevelNumber = Me.LevelNumber + 1
        GoToLevel LevelNumber
    End If
End Function

'====================================================================================
'StartLevelCompleteScreen: Show the "Level Complete" screen
'====================================================================================
Public Function StartLevelCompleteScreen()
    'Create the Level Complete screen class
    Set GameScreen = New IScreen_LevelComplete
    
    'Tell the drawing and animating routines to handle the level complete screen
    GameMode = GM_LvlComplete
End Function

'=== END ============================================================================
'This work is licenced under the Creative Commons Attribution 2.5 License
